package sz.szsmk.citizencard.ui.newversion.fragment.presenter

import sz.szsmk.citizencard.DaggerApplication
import sz.szsmk.citizencard.model.network.bean.request.AccessTokenRequest
import sz.szsmk.citizencard.model.network.bean.response.BaseBean
import sz.szsmk.citizencard.model.network.bean.response.UserBean
import sz.szsmk.citizencard.model.network.dzbean.req.BaseRequest
import sz.szsmk.citizencard.mvp.dzsmkpresenter.AppBasePresenter
import sz.szsmk.citizencard.mvp.presenter.IBasePresenter
import sz.szsmk.citizencard.retrofitrxjava.newversion.ApiCallback
import sz.szsmk.citizencard.retrofitrxjava.newversion.HttpDateSource
import sz.szsmk.citizencard.smkretrofit.NetworkDateSource
import sz.szsmk.citizencard.ui.newversion.bean.AppealTypeVoListBean
import sz.szsmk.citizencard.ui.newversion.bean.InsertAppealInfoBean
import sz.szsmk.citizencard.ui.newversion.fragment.view.LogoffMvpView
import sz.szsmk.citizencard.util.ACache
import javax.inject.Inject

/**
 *  author : hyt
 *  date : 2020/8/12
 *  description :
 */
class LogoffPresenter@Inject constructor(var httpDateSourceNotUse: NetworkDateSource)
    : AppBasePresenter<LogoffMvpView>() {


    //查询销户类型
    fun queryAppealType(){
        var temp = BaseRequest()
        temp.accessToken = ACache.get(DaggerApplication.getIns()).getAsString("access_token")

        addSubscription(HttpDateSource.createApi()?.queryAppealType(temp) , object : ApiCallback<AppealTypeVoListBean?> {
            override fun onSuccess(response: AppealTypeVoListBean?) {
                response?.let {
                    mvpView.AppealTypeVoListonSuccess(it)
                }
            }

            override fun onFailure(model: BaseBean?, e: Throwable?) {
                model?.let { mvpView.onFail(it) }
            }
        })
    }

    fun insertAppealInfo(insertAppealInfoBean: InsertAppealInfoBean){

        addSubscription(HttpDateSource.createApi()?.insertAppealInfo(insertAppealInfoBean)
                , object : ApiCallback<BaseBean?> {
            override fun onSuccess(response: BaseBean?) {
                response?.let {
                    mvpView.onLogoffSuccess(it)
                }
            }

            override fun onFailure(model: BaseBean?, e: Throwable?) {
                model?.let { mvpView.onFail(it) }
            }
        })
    }
}